{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<div class="tablesWrap">  
    <div class="tables-searchbox">  
        <a href="/AcpConfig/add_link" class="btn btn-blue"><i class="gicon-plus white"></i>添加友情链接</a>
    </div>  
    <!-- end tables-searchbox -->  
    <table class="wxtables">  
        <colgroup>  
        <col width="10%">  
        <col width="25%">  
        <col width="25%">  
        <col width="10%">  
        <col width="10%">  
        <col width="20%">  
        </colgroup>  
        <thead>  
            <tr>  
                <td>LOGO</td>  
                <td>网站名称</td>  
                <td>网站网址</td>  
                <td>排列顺序</td>  
                <td>是否显示</td>  
                <td>操作</td>  
            </tr>  
        </thead>  
        <tbody>  
		{if $link_list}
		{foreach from=$link_list item=this}
            <tr>  
                <td style="position: relative;">
					<img src="__IMAGES__/popup-loading.gif" style="display: none; position: absolute; z-index: 999; width: 32px; height: 32px; left: 19px; top: 19px;" />
					<img class="J_Thumbnail" src="__ACPIMAGES__/nopicture.jpg" data-url="{$this.link_logo}" width="50" height="50" />
				</td>  
                <td><a href="{$this.link_url}" target="_blank">{$this.link_name}</a></td>  
                <td><a href="{$this.link_url}" target="_blank">{$this.link_url}</a></td>  
                <td class="serial">
					<img src="__IMAGES__/ajax-loading.gif" class="hide" />
					<input type="text" title="点击更改排序" style="width:40px; text-align:center; border-color: #fff;" value="{$this.serial}" onblur="setSerial({$this.link_id}, this);">
				</td>  
                <td>
					<img src="__IMAGES__/ajax-loading.gif" class="hide" />
				{if $this.isuse eq 1}
					<a href="javascript:;" title="点击禁用" onclick="setUse({$this.link_id}, this);"><i class="gicon-ok black"></i></a>
				{elseif $this.isuse eq 0}
					<a href="javascript:;" title="点击启用" onclick="setUse({$this.link_id}, this);"><i class="gicon-remove black"></i></a>
				{/if}
				</td>   
                <td>   
                    <a href="/AcpConfig/edit_link/id/{$this.link_id}" class="btn" title="修改"><i class="gicon-edit black"></i>编辑</a>   
                    <a href="javascript:;" class="btn J_Del" data-id="{$this.link_id}" title="删除"><i class="gicon-trash black"></i>删除</a>   
                </td>  
            </tr>
		{/foreach}
		{else}
			<tr>
				<td colspan="6" style="text-align: center;">暂无友情链接，您可以<a href="/AcpConfig/add_link">添加友情链接</td>
			</tr>
		{/if}
        </tbody>  
    </table>  
    <!-- end wxtables -->  
    <div class="tables-btmctrl clearfix">  
        <div class="fl">  
           
        </div>  
        <div class="fr">  
            <div class="paginate">  
                {$pagination}
            </div>  
            <!-- end paginate -->  
        </div>  
    </div>  
    <!-- end tables-btmctrl -->  
</div>  
<!-- end tablesWrap -->   
{/block} 

{block name="js"}
{literal}
<script type="text/javascript">
$(function(){
	$('.serial input').mouseenter(function(){
		$(this).css('cursor', 'pointer');
	})
	.click(function(){
		$(this).css('cursor', 'text');
		$(this).css('border-color', '#72b7cd');
	})
	.blur(function(){
		$(this).css('border-color', '#fff');
	});
	
	var imgUrl = '';
	$('.J_Thumbnail').each(function(){
		imgUrl = $(this).data('url');
		if ('' != imgUrl) {
			$(this).attr('src', imgUrl);
		}
	});
	
	$('.J_Del').on('click', function(){
		var _this = this;
		var _id = $(this).data('id');
		
		$.jPops.confirm({
			title:"提示",
			content:'您确定要删除这条数据吗？',
			okBtnTxt:"确定",
			cancelBtnTxt:"取消",
			callback:function(r){
				if (r) {
					$.ajax({
						url: '/AcpConfigAjax/del_link',
						data: {id: _id},
						dataType: 'json',
						beforeSend: function(){
							$.jPops.showLoading();
						},
						success: function(data){
							$.jPops.hideLoading();
							if (data.status === 1) {
								$(_this).parents('tr').fadeOut(400, function(){
									$(this).remove();
								});
							}
							$.jPops.alert({
								title:"提示",
								content:data.msg,
								okBtnTxt:"确定",
								callback:function(){
									return true;
								}
							});
						}
					});
				}
				return true;
			}
		});
	});
});

function setUse(_id, _this){
	$.ajax({
		url: '/AcpConfigAjax/edit_link_isuse',
		data: {id: _id},
		dataType: 'json',
		beforeSend: function(){
			$(_this).prev().removeClass('hide');
			$(_this).children().addClass('hide');
		},
		success: function(data){
			$(_this).prev().addClass('hide');
			if (data.isuse === 0) {
				$(_this).children().attr('class', 'gicon-remove black')
			}
			else if (data.isuse === 1) {
				$(_this).children().attr('class', 'gicon-ok black');
			}
		}
	});
}

function setSerial(_id, _this){
	var initVal = _this.defaultValue;
	var curVal = $(_this).val();
	if (curVal == '') {
		$(_this).val(initVal);
		return false;
	}
	if (curVal == initVal) {
		return false;
	}
	
	$.ajax({
		url: '/AcpConfigAjax/edit_link_serial',
		data: {id: _id, serial: curVal},
		dataType: 'json',
		beforeSend: function(){
			$(_this).prev().removeClass('hide');
			$(_this).addClass('hide');
		},
		success: function(data){
			$(_this).prev().addClass('hide');
			$(_this).removeClass('hide');
			if (data.status === 1) {
				_this.defaultValue = curVal;
			}
			else {
				$(_this).val(initVal);
			}
			$.jPops.alert({
				title:"提示",
				content:data.msg,
				okBtnTxt:"确定",
				callback:function(){
					return true;
				}
			});
		}
	});
}
</script>
{/literal}
{/block} 

{block name="css"}

{/block}
